package com.xinqi.modules.prepare.video.controller.web;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoCreateDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoQueryDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoUpdateDTO;
import com.xinqi.modules.prepare.video.dto.rsp.PrepareVideoResultDTO;
import com.xinqi.modules.prepare.video.service.PrepareVideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 备课区互动视频Web控制层
 *
 * @author: system
 * @date: 2023/03/19
 */
@Tag(name = "Web-备课区-互动视频", description = "备课区-互动视频Web接口")
@RestController
@RequestMapping("/web/prepare")
@RequiredArgsConstructor
public class PrepareVideoWebController {
    private final PrepareVideoService prepareVideoService;


    /**
     * 备课区互动视频-分页
     */
    @Operation(summary = "备课区互动视频-分页")
    @GetMapping("/{prepare-id}/video/page")
    public R<PageInfo<PrepareVideoResultDTO>> page(@Parameter(description = "备课区id", example = "100001") @PathVariable("prepare-id") Long prepareId,
                                                   @ParameterObject PrepareVideoQueryDTO dto) {
        dto.setPrepareId(prepareId);
        PageInfo<PrepareVideoResultDTO> page = prepareVideoService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 备课区互动视频-详情
     */
    @Operation(summary = "备课区互动视频-详情")
    @GetMapping("/{prepare-id}/video/{id}")
    public R<PrepareVideoResultDTO> findById(@Parameter(description = "备课区id", example = "100001") @PathVariable("prepare-id") Long prepareId,
                                             @Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        PrepareVideoResultDTO dto = prepareVideoService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增备课区互动视频
     */
    @Operation(summary = "新增备课区互动视频")
    @PostMapping("/{prepare-id}/video")
    public R<Long> insert(@Parameter(description = "备课区id", example = "100001") @PathVariable("prepare-id") Long prepareId,
                          @RequestBody PrepareVideoCreateDTO dto) {
        dto.setPrepareId(prepareId);
        return R.data(prepareVideoService.insert(dto));
    }

    /**
     * 修改备课区互动视频
     */
    @Operation(summary = "修改备课区互动视频")
    @PutMapping("/{prepare-id}/video/{id}")
    public R<Boolean> update(@Parameter(description = "备课区id", example = "100001") @PathVariable("prepare-id") Long prepareId,
                             @Parameter(description = "id", example = "100001") @PathVariable("id") Long id, @RequestBody PrepareVideoUpdateDTO dto) {
        dto.setId(id);
        return R.data(prepareVideoService.updateById(dto));
    }

    /**
     * 删除备课区互动视频
     */
    @Operation(summary = "删除备课区互动视频")
    @DeleteMapping("/{prepare-id}/video/{id}")
    public R<Boolean> delete(@Parameter(description = "备课区id", example = "100001") @PathVariable("prepare-id") Long prepareId,
                             @Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        return R.data(prepareVideoService.deleteById(id), "删除成功");
    }

}
